libobs_sources\windows\sources/window_capture.rs
1use libobs_source_macro::obs_object_impl;
2#[cfg(feature = "window-list")]
3use libobs_window_helper::{get_all_windows, WindowInfo, WindowSearchMode};
4use libobs_wrapper::sources::{ObsSourceRef, ObsSourceBuilder};
5
6use crate::macro_helper::define_object_manager;
7
8use super::{ObsWindowCaptureMethod, ObsWindowPriority};
9
10define_object_manager!(
11 /// Provides a easy to use builder for the window capture source.
12 #[derive(Debug)]
13 struct WindowCaptureSource("window_capture") for ObsSourceRef {
14 #[obs_property(type_t = "enum")]
15 /// Sets the capture method for the window capture
16 capture_method: ObsWindowCaptureMethod,
17
18 /// Sets the priority of the window capture source.
19 /// Used to determine in which order windows are searched for.
20 ///
21 /// # Arguments
22 ///
23 /// * `priority` - The priority of the window capture source.
24 ///
25 /// # Returns
26 ///
27 /// The updated `WindowCaptureSourceBuilder` instance.
28 #[obs_property(type_t = "enum")]
29 priority: ObsWindowPriority,
30
31 /// Sets the window to capture.
32 ///
33 /// # Arguments
34 ///
35 /// * `window` - The window to capture, represented as `ObsString`. Must be in the format of an obs window id
36 ///
37 /// # Returns
38 ///
39 /// The updated `WindowCaptureSourceBuilder` instance.
40 #[obs_property(type_t = "string", settings_key = "window")]
41 window_raw: String,
42
43 #[obs_property(type_t = "bool")]
44 /// Sets whether the cursor should be captured
45 cursor: bool,
46
47 #[obs_property(type_t = "bool")]
48 /// Whether to capture audio from window source (BETA) <br>
49 /// When enabled, creates an "Application Audio Capture" source that automatically updates to the currently captured window/application. <br>
50 /// Note that if Desktop Audio is configured, this could result in doubled audio.
51 capture_audio: bool,
52
53 #[obs_property(type_t = "bool")]
54 /// Whether to force SDR color space for the window capture source.
55 force_sdr: bool,
56
57 #[obs_property(type_t = "bool")]
58 /// Whether to capture the window's client area only (without borders, title bar and the main menu bar).
59 client_area: bool,
60
61 #[obs_property(type_t = "bool")]
62 compatibility: bool,
63});
64
65#[obs_object_impl]
66#[cfg(feature = "window-list")]
67impl WindowCaptureSource {
68 /// Gets a list of windows that can be captured by this source.
69 pub fn get_windows(mode: WindowSearchMode) -> anyhow::Result<Vec<WindowInfo>> {
70 get_all_windows(mode)
71 }
72
73 /// Sets the window to capture.
74 ///
75 /// # Arguments
76 ///
77 /// * `window` - The window to capture. A list of available windows can be retrieved using `WindowCaptureSourceBuilder::get_windows`
78 ///
79 /// # Returns
80 ///
81 /// The updated `WindowCaptureSourceBuilder` instance.
82 pub fn set_window(self, window: &WindowInfo) -> Self {
83 self.set_window_raw(window.obs_id.as_str())
84 }
85}
86
87impl ObsSourceBuilder for WindowCaptureSourceBuilder {}